package com.lk.api.app;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.widget.Button;

/**
 * Created by lk on 2014/12/22.
 */
public class MyCustomEvent extends Button {


    public MyCustomEvent(Context context) {
        super(context);
    }

    public MyCustomEvent(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    //    回调画布方法
    @Override
    protected void onDraw(Canvas canvas) {
//        创建画笔
        Paint plane = new Paint();
//        设置画笔颜色
        plane.setColor(Color.RED);
//        画矩形
        canvas.drawRect(5, 5, 25, 25, plane);
        super.onDraw(canvas);
    }


    private MyOnKeyDown mMyOnKeyDown;

    //定义键盘按下接口
    interface MyOnKeyDown {
        //        接口键盘按下方法
        public void onKeyDown(String KeyObject);
    }

    // 键盘按下事件方法
    public void setOnKeyDown(MyOnKeyDown on) {
        mMyOnKeyDown = on;
    }

    //    键盘按下事件
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        mMyOnKeyDown.onKeyDown("hello");
        return super.onKeyDown(keyCode, event);
    }
}
